package com.ybwh.springboot2.controller;

import com.ybwh.springboot2.common.RespData;
import com.ybwh.springboot2.dao.AreaMapper;
import com.ybwh.springboot2.model.vo.AreaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author saytime
 * @since 2018-12-06
 */
@Api("地区")
@Controller
@RequestMapping("/area")
public class AreaController {

    @Autowired
    private AreaMapper areaMapper;

    @ResponseBody
    @RequestMapping(value = "/validate", method = RequestMethod.GET)
    public RespData<Object> validate(@Validated @ModelAttribute @RequestBody AreaVo areaVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            for (ObjectError error : bindingResult.getAllErrors()) {
                return RespData.failedResp(error.getDefaultMessage());
            }
        }

        return RespData.successResp(null);
    }

    @ResponseBody
    @RequestMapping(value = "/validate2", method = RequestMethod.GET)
    public RespData<Object> validate2(@ApiParam(value = "参数data2") @RequestParam("data2") String data) {


        return RespData.successResp(null);
    }


    @ResponseBody
    @RequestMapping(value = "/getArea", method = RequestMethod.GET)
    public RespData<Object> getArea(@ApiParam(value = "id") @RequestParam("id") Long id) {

        return RespData.successResp(areaMapper.selectById(id));
    }


}
